<?php 

namespace app\controller\api;

use app\exception\ErrnoPlus;
use Exception;
use share\controller\ApiBaseController;
use share\exception\ApiException;
use share\exception\PageException;
use share\service\AliCloudService;
use share\utils\Helper;

class DataflowController extends ApiBaseController{

    public function initValidate(){    
    }

    /**
     * 领取免费流量
     */
    public function get_free_action(){
        $iccid = request()->param("iccid");
        if(!$iccid){
            throw new ApiException("参数异常",ErrnoPlus::PARAM_ERROR);
        }
        try{
            $res = AliCloudService::prePackage($iccid, 1);
            if($res){
                return self::ok(null,'领取成功');
            }
            return self::fail(null,'领取失败',ErrnoPlus::COMMON_ERROR);
        }
        catch(Exception $e){
            return self::fail(null,$e->getMessage(),ErrnoPlus::COMMON_ERROR);
        }
    }

}